home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / Window / c / Show < prev    next >
Text File  |  1995-07-12  |  4KB  |  136 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Window.Show.c
  12.     Author:  Copyright © 1992 Jason Williams
  13.     Version: 1.00 (19 Mar 1992)
  14.     Purpose: High-level window management functions: Show a window
  15. */
  16.  
  17.  
  18. #include "DeskLib:WimpSWIs.h"
  19. #include "DeskLib:Window.h"
  20. #include "DeskLib:Screen.h"
  21.  
  22. static wimp_point lastopenpos = {-1, -1};
  23.  
  24.  
  25. extern void Window_Show(window_handle window, window_openpos openpos)
  26. {
  27.   window_state  wstate;
  28.   wimp_point    moveto = {0, 0};
  29.   int           w, h;
  30.  
  31.   Screen_CacheModeInfo();            /* Ensure got correct screen mode info. */
  32.  
  33.   Wimp_GetWindowState(window, &wstate);
  34.   wstate.openblock.behind = -1;                             /* open in front */
  35.  
  36.   w = wstate.openblock.screenrect.max.x - wstate.openblock.screenrect.min.x;
  37.   h = wstate.openblock.screenrect.max.y - wstate.openblock.screenrect.min.y;
  38.                                         
  39.   switch(openpos)
  40.   {
  41.     case open_CENTERED:
  42.       moveto.x = (screen_size.x - w) / 2;
  43.       moveto.y = (screen_size.y + h) / 2;
  44.       break;
  45.       
  46.     case open_CENTEREDUNDERPOINTER:
  47.       {
  48.         mouse_block ptr;
  49.  
  50.         Wimp_GetPointerInfo(&ptr);
  51.         moveto.x = ptr.pos.x - (w / 2);
  52.         moveto.y = ptr.pos.y + (h / 2);
  53.       }
  54.       break;
  55.  
  56.     case open_OVERCARET:
  57.       {
  58.         caret_block  caret;
  59.         window_state wstate;
  60.  
  61.         Wimp_GetCaretPosition(&caret);
  62.  
  63.         if (caret.window > 0)
  64.         {
  65.           Wimp_GetWindowState(caret.window, &wstate);
  66.  
  67.           moveto.x = wstate.openblock.screenrect.min.x +
  68.                      (caret.offset.x - wstate.openblock.scroll.x) - 64;
  69.           moveto.y = wstate.openblock.screenrect.max.y -
  70.                      (caret.offset.y - wstate.openblock.scroll.y) + 64;
  71.         }
  72.         else
  73.         {
  74.           /* No caret, so just open centered on screen */
  75.           moveto.x = (screen_size.x - w) / 2;
  76.           moveto.y = (screen_size.y + h) / 2;
  77.         }
  78.       }
  79.       break;
  80.  
  81.     case open_UNDERPOINTER:
  82.       {
  83.         mouse_block ptr;
  84.  
  85.         Wimp_GetPointerInfo(&ptr);
  86.         moveto.x = ptr.pos.x - 64;
  87.         moveto.y = ptr.pos.y + 64;
  88.       }
  89.       break;
  90.  
  91.     case open_NEARLAST:
  92.       if (lastopenpos.x >= 0)
  93.       {
  94.         moveto.x = lastopenpos.x + 16;
  95.         moveto.y = lastopenpos.y - 16;
  96.       }
  97.       else
  98.       {
  99.         moveto.x = (screen_size.x - w) / 2;
  100.         moveto.y = (screen_size.y + h) / 2;
  101.       }
  102.       
  103.       if (moveto.x > ((screen_size.x / 2) + 128))
  104.         moveto.x = (screen_size.x / 2) - 128;
  105.  
  106.       if (moveto.y < ((screen_size.y / 2) - 128))
  107.         moveto.y = (screen_size.y / 2) + 128;
  108.       break;
  109.  
  110.     default:
  111.       /* Open wherever it is defined in the template file. */
  112.       moveto.x = wstate.openblock.screenrect.min.x;
  113.       moveto.y = wstate.openblock.screenrect.max.y;
  114.       break;
  115.   }
  116.  
  117.   if (moveto.x < 0)  moveto.x = 0;
  118.   if (moveto.y < 64) moveto.y = 64;
  119.   if (moveto.x > screen_size.x - 96) moveto.x = screen_size.x - 96;
  120.   if (moveto.y > screen_size.y - 32) moveto.y = screen_size.y - 32;
  121.  
  122.   wstate.openblock.screenrect.min.x = moveto.x;
  123.   wstate.openblock.screenrect.max.y = moveto.y;
  124.  
  125.   wstate.openblock.screenrect.max.x = wstate.openblock.screenrect.min.x + w;
  126.   wstate.openblock.screenrect.min.y = wstate.openblock.screenrect.max.y - h;
  127.  
  128.   if (openpos == open_NEARLAST)
  129.   {
  130.     lastopenpos.x = wstate.openblock.screenrect.min.x;  /* save last open pos*/
  131.     lastopenpos.y = wstate.openblock.screenrect.max.y;
  132.   }
  133.  
  134.   Wimp_OpenWindow(&wstate.openblock);
  135. }
  136.